import {
    colorUISdk
} from "../../config/mp-sdk";
import {updateCurrentPageShare} from "../../mp-sdk/lib/share";

const app = getApp();
let interstitialAd = null
Page({
    data: {
        customStyle: {
            card: {
                'background-color': '#FAFAFA',
            },
            title: {
                color: 'rgba(0, 0, 0, 0.8)',
            },
            price: {
                color: '#FF6146'
            },
            'buy-button': {
                width: 'r100px',
                'border-radius': '30rpx',
                'background-color': 'rgb(253,96,69)',
                color: '#ffffff',
            },
            'buy-button-disabled': {
                width: 'r100px',
                'border-radius': '30rpx',
              'background-color': 'rgb(253,96,69)',
              color: '#ffffff',
            },
        },
        marqueeText: ' 感谢车友们的鼎立支持,本公司郑重承诺：一次购买 永久使用！让车友们用的 安心、放心、省心！！！',
        marqueeDistance: 0,
        marqueeSpeed: 0.8,
        marqueeWidth: 0,
        windowWidth: 0
    },
    onLoad() {
        const query = wx.createSelectorQuery();
        query.select('.coco-marquee-text').boundingClientRect();
        query.select('.coco-marquee-container').boundingClientRect();
        query.exec((res) => {
            if (res[0] && res[1]) {
                this.setData({
                    marqueeWidth: res[0].width,
                    windowWidth: res[1].width
                });
                this.startMarquee();
            }
        });
        // 登录成功后立即更新分享配置
        updateCurrentPageShare();
    },

    startMarquee() {
        this._marqueeTimer = setInterval(() => {
            let distance = this.data.marqueeDistance + this.data.marqueeSpeed;
            if (distance >= this.data.marqueeWidth + this.data.windowWidth) {
                distance = 0;
            }
            this.setData({
                marqueeDistance: distance
            });
        }, 16);
    },

    onUnload() {
        if (this._marqueeTimer) {
            clearInterval(this._marqueeTimer);
        }
    }
})
